<?php
class DB extends PDO {
		
    public function __construct(){    	
        try{
        	PDO::__construct('mysql:host='.DB_HOST.';dbname='.DB_NAME.'', DB_USER, DB_PASS);
           	$this->exec("set names utf8");
           //$this->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING);
           //$this->setFetchMode(PDO::FETCH_ASSOC);
       
        }catch(PDOException $e){
            die ("Error!: " . $e->getMessage());
        }
    }
    /* *
     * 添加 ($sql)
     * */
	public function Insert($sql){
		if($sql && !empty($sql)){
			try{
				$this->exec("$sql");
				return true;   
			}catch(Exception $e){
	   			echo "error:".$e->getMessage();
	  		}
		}
	}
    /* *
     * 删除 ($sql)
     * */
	public function delete($sql){
		if($sql && !empty($sql)){
			try{
				$this->exec("$sql");
				return true;   
			}catch(Exception $e){
	   			echo "error:".$e->getMessage();
	  		}
		}
	}
    /* *
     * 更新 ($sql)
     * */
	public function update($sql){
		if($sql && !empty($sql)){
			try{
				$this->exec("$sql");   
				return true;
		}catch(Exception $e){
	   			echo "error:".$e->getMessage();
	  		}
		}
	}
    /* *
     * 查询 ($sql)
     * */
	public function select($sql){
		if($sql && !empty($sql)){
			try{
				$result = $this->query("$sql");
				return $result->fetchAll(PDO::FETCH_ASSOC);
			}catch(Exception $e){
	   			echo "error:".$e->getMessage();
	  		}
		}
	}
	
	/**
	 * 选数据表
	 * 
	 * @param $name	表名
	 */
	public function getTableName($name){
		//include_once PATH_CONFIG.DS.'database.inc.php';

		return $name;
	}
}
?> 